<%@page import="cn.jhc.dao.MsgDao"%>
<%@page import="cn.jhc.dao.ConnectionFactory"%>
<%@page import="cn.jhc.bean.MsgBean"%>
<%@page import="java.util.ArrayList"%>
<%@page import="cn.jhc.bean.UserBean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="./css/taolunqu.css"></link>
<title>留言板</title>
</head>
<body>
	<%
		int CurrentPage = 1;
		int titleCount = 15;
		int intPageCount;
		if (request.getParameter("page") != null)
			CurrentPage = Integer.parseInt(request.getParameter("page"));
		if (CurrentPage < 1)
			CurrentPage = 1;
		int MsgCount;
	%>

	<div id="wrapper">
		<jsp:include page="./header.jsp"></jsp:include>
		<div id="address">
			<a>当前位置：　讨论区 > 灌水区</a>
		</div>
		<div id="wrapperdown">
		<%
			ArrayList<MsgBean> m = new ArrayList<MsgBean>();
			MsgDao dao = new MsgDao();
			dao.setCon(ConnectionFactory.getConnection());
			m = dao.getAllMessages(CurrentPage, titleCount);
			request.setAttribute("title", m);
		%>
		<%
			ArrayList<MsgBean> b = new ArrayList<MsgBean>();
			MsgDao dao3 = new MsgDao();
			dao3.setCon(ConnectionFactory.getConnection());
			b = dao3.getBetterMessages();
			request.setAttribute("better", b);
		%>
		<%
			ArrayList<MsgBean> t = new ArrayList<MsgBean>();
			MsgDao dao4 = new MsgDao();
			dao4.setCon(ConnectionFactory.getConnection());
			t = dao4.getTopMessages();
			request.setAttribute("top", t);
		%>
		<%
			MsgDao dao2 = new MsgDao();
			dao2.setCon(ConnectionFactory.getConnection());
			intPageCount = dao2.getCount(titleCount);
			if(intPageCount==0){
				CurrentPage=1;
				intPageCount=1;
			}else{
				if (CurrentPage > intPageCount)
					CurrentPage = intPageCount;
			}
		%>
		<div id="right_news">
			<table width="1000" align="left">
				<tr>
					<th height="25">标题</th>
					<th>时间</th>
					<th>发表</th>
					<th>回复</th>
				</tr>
				<%
					if (CurrentPage == 1) {
				%>
				<%
					ArrayList list = (ArrayList) request.getAttribute("top");
						if (list != null) {
							for (int i = 0; i < list.size(); i++) {
								MsgBean top = (MsgBean) list.get(i);
				%>
				<tr>
					<td width="70%" height="30"><a
						href="showmessages.jsp?id=<%=top.getId()%>">[置顶]<%=top.getTitle()%></a>
					<td><div align="center"><%=top.getDate()%></div></td>
					<td><div align="center"><%=top.getDisplayname()%></div></td>
					<%
						MsgDao dao5 = new MsgDao();
									dao5.setCon(ConnectionFactory.getConnection());
									MsgCount = dao5.getMsgCount(top.getId());
					%>
					<td><div align="center"><%=MsgCount%></div></td>
				</tr>
				<%
					}
						}
				%>
				<%
					ArrayList bet = (ArrayList) request.getAttribute("better");
						if (bet != null) {
							for (int i = 0; i < bet.size(); i++) {
								MsgBean bett = (MsgBean) bet.get(i);
				%>
				<tr>
					<td width="70%" height="30"><a
						href="showmessages.jsp?id=<%=bett.getId()%>">[精华]<%=bett.getTitle()%></a>
					<td><div align="center"><%=bett.getDate()%></div></td>
					<td><div align="center"><%=bett.getDisplayname()%></div></td>
					<%
						MsgDao dao5 = new MsgDao();
									dao5.setCon(ConnectionFactory.getConnection());
									MsgCount = dao5.getMsgCount(bett.getId());
					%>
					<td><div align="center"><%=MsgCount%></div></td>
				</tr>
				<%
					}
						}
				%>
				<%
					}
				%>
				<%
					ArrayList ti = (ArrayList) request.getAttribute("title");
					if (ti != null) {
						for (int i = 0; i < ti.size(); i++) {
							MsgBean tit = (MsgBean) ti.get(i);
				%>
				<tr>
					<td width="70%" height="30"><a
						href="showmessages.jsp?id=<%=tit.getId()%>">[普通]<%=tit.getTitle()%></a>
					<td><div align="center"><%=tit.getDate()%></div></td>
					<td><div align="center"><%=tit.getDisplayname()%></div></td>
					<%
						MsgDao dao5 = new MsgDao();
								dao5.setCon(ConnectionFactory.getConnection());
								MsgCount = dao5.getMsgCount(tit.getId());
					%>
					<td><div align="center"><%=MsgCount%></div></td>
				</tr>
				<%
					}
					}
				%>
			</table>
		</div>
		<div id="button">
			<form method="post" action="./msg.jsp">
				<input type="hidden" name="getb" value="/taolunqu.jsp"> <input
					type="submit" value="开启一个新话题"></input>
			</form>
		</div>
		<div align="right">
			<a>第<%=CurrentPage%>页 共<%=intPageCount%>页
			</a> <a href="taolunqu.jsp?page=<%=1%>">首页</a>
			<%
				if (CurrentPage > 1) {
			%>
			<a href="taolunqu.jsp?page=<%=CurrentPage - 1%>">上一页</a>
			<%
				} else {
			%>
			上一页
			<%
				}
			%>
			<%
				if (CurrentPage >= intPageCount) {
			%>
			下一页
			<%
				} else {
			%>
			<a href="taolunqu.jsp?page=<%=CurrentPage + 1%>">下一页</a>
			<%
				}
			%>
			<a href="taolunqu.jsp?page=<%=intPageCount%>">末页</a>
		</div>
		</div>
		<jsp:include page="./copyright.jsp"></jsp:include>
	</div>
</body>
</html>




